package models;

import java.util.ArrayList;
import java.util.List;

import org.bson.types.ObjectId;

import play.modules.mongo.MongoEntity;
import play.modules.mongo.MongoModel;

@MongoEntity("groups")
public class Group extends MongoModel {
		
	public String getName() {
		return get("name");
	}
	public void setName(String name) {
		set("name",name);
	}
	
	public List<String> getMembers() {
		if(!has("members")){
			setMembers(new ArrayList<String>());
		}
		return get("members");
	}
	
	public void setMembers(List<String> value) {
		set("members",value);
	}
	
	public static Group getById(String id){
		return (Group) Group.find("by_id", id).first();
	}
	
	public static Boolean addMember(Group g, User u){
	/*	Group o = getById(u.getGroup());
		o.getMembers().remove(u.getId());
		o.save();*/
		u.setGroupID(g.getId());
		u.save();
		g.getMembers().add(u.getId());
		g.save();
		return true;
	}
	
}
